package com.yourcompany.service.task;

import com.yourcompany.api.service.CreditPayService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import lombok.extern.slf4j.Slf4j;

@Component
@EnableScheduling
@Slf4j
public class CreditScheduleTask {
    
    @Autowired
    private CreditPayService creditPayService;
    
    /**
     * 每天凌晨1点检查逾期
     */
    @Scheduled(cron = "0 0 1 * * ?")
    public void checkOverdue() {
        log.info("开始检查逾期情况");
        try {
            creditPayService.checkAndHandleOverdue();
        } catch (Exception e) {
            log.error("检查逾期异常", e);
        }
    }
    
    /**
     * 每月1号凌晨2点调整信用额度
     */
    @Scheduled(cron = "0 0 2 1 * ?")
    public void adjustCreditLimit() {
        log.info("开始调整信用额度");
        try {
            creditPayService.autoAdjustCreditLimit();
        } catch (Exception e) {
            log.error("调整信用额度异常", e);
        }
    }
} 